import asyncio, asyncpg


async def main():
    connection = await asyncpg.connect(
        host="127.0.0.1",
        port="5432",
        database="products",
        user="around",
        password="zhouwei",
    )

    async with connection.transaction():
        query = "select * from product"
        # 为查询创建游标
        cursor = await connection.cursor(query)
        # 将游标向前移动500条记录
        await cursor.forward(500)
        # 获取接下来的100条记录
        products = await cursor.fetch(100)
        for product in products:
            print(product)

    await connection.close()


asyncio.run(main())
